inspector: Reshuffle Visual and General tabs
authorMatthias Clasen <mclasen@redhat.com>
Sat, 12 Jul 2014 05:43:03 +0000 (01:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Jul 2014 05:45:44 +0000 (01:45 -0400)
Move the touchscreen switch to the other debug switches, and
move the hidpi spin to the other graphical controls. Since the
Visual tab is getting large, make it scroll. The General tab
is purely informational again.

gtk/inspector/general.c
gtk/inspector/general.ui
gtk/inspector/visual.c
gtk/inspector/visual.h
gtk/inspector/visual.ui

index 54002ea5fa226080960675bdfcff8e71765af5bd..773ef889a12d7667d1d5ea983162bcf51d5a132d 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "general.h"
 
-#include "gtkadjustment.h"
 #include "gtkdebug.h"
 #include "gtklabel.h"
 #include "gtkscale.h"
@@ -61,9 +60,6 @@ struct _GtkInspectorGeneralPrivate
   GtkWidget *gtk_exe_prefix;
   GtkWidget *gtk_data_prefix;
   GtkWidget *gsettings_schema_dir;
-  GtkWidget *hidpi_spin;
-  GtkWidget *touchscreen_switch;
-  GtkAdjustment *scale_adjustment;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorGeneral, gtk_inspector_general, GTK_TYPE_BOX)
@@ -149,72 +145,6 @@ init_env (GtkInspectorGeneral *gen)
   set_path_label (gen->priv->gsettings_schema_dir, "GSETTINGS_SCHEMA_DIR");
 }
 
-static void
-update_touchscreen (GtkSwitch *sw, GParamSpec *pspec, GtkInspectorGeneral *gen)
-{
-  GtkDebugFlag flags;
-
-  flags = gtk_get_debug_flags ();
-
-  if (gtk_switch_get_active (sw))
-    flags |= GTK_DEBUG_TOUCHSCREEN;
-  else
-    flags &= ~GTK_DEBUG_TOUCHSCREEN;
-
-  gtk_set_debug_flags (flags);
-}
-
-#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
-static void
-scale_changed (GtkAdjustment *adjustment, GtkInspectorGeneral *gen)
-{
-  GdkDisplay *display;
-  gint scale;
-
-  scale = gtk_adjustment_get_value (adjustment);
-  display = gtk_widget_get_display (GTK_WIDGET (gen));
-  gdk_x11_display_set_window_scale (display, scale);
-}
-#endif
-
-static void
-init_settings (GtkInspectorGeneral *gen)
-{
-#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
-  GdkScreen *screen;
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (gen));
-  if (GDK_IS_X11_SCREEN (screen))
-    {
-      gdouble scale;
-
-      scale = gdk_screen_get_monitor_scale_factor (screen, 0);
-      gtk_adjustment_set_value (gen->priv->scale_adjustment, scale);
-      g_signal_connect (gen->priv->scale_adjustment, "value-changed",
-                        G_CALLBACK (scale_changed), gen);
-    }
-  else
-#endif
-    {
-      gtk_adjustment_set_value (gen->priv->scale_adjustment, 1);
-      gtk_widget_set_sensitive (gen->priv->hidpi_spin, FALSE);
-      gtk_widget_set_tooltip_text (gen->priv->hidpi_spin,
-                                   _("Backend does not support window scaling"));
-    }
-
-  gtk_switch_set_active (GTK_SWITCH (gen->priv->touchscreen_switch), (gtk_get_debug_flags () & GTK_DEBUG_TOUCHSCREEN) != 0);
-  g_signal_connect (gen->priv->touchscreen_switch, "notify::active",
-                    G_CALLBACK (update_touchscreen), gen);
-
-  if (g_getenv ("GTK_TEST_TOUCHSCREEN") != 0)
-    {
-      /* hardcoded, nothing we can do */
-      gtk_switch_set_active (GTK_SWITCH (gen->priv->touchscreen_switch), TRUE);
-      gtk_widget_set_sensitive (gen->priv->touchscreen_switch, FALSE);
-      gtk_widget_set_tooltip_text (gen->priv->touchscreen_switch, _("Setting is hardcoded by GTK_TEST_TOUCHSCREEN"));
-    }
-}
-
 static void
 gtk_inspector_general_init (GtkInspectorGeneral *gen)
 {
@@ -222,7 +152,6 @@ gtk_inspector_general_init (GtkInspectorGeneral *gen)
   gtk_widget_init_template (GTK_WIDGET (gen));
   init_version (gen);
   init_env (gen);
-  init_settings (gen);
 }
 
 static void
@@ -240,9 +169,6 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_exe_prefix);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_data_prefix);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gsettings_schema_dir);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, hidpi_spin);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, scale_adjustment);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, touchscreen_switch);
 }
 
 // vim: set et sw=2 ts=2:
index b20020a7c7d2a75c0ed0c2422fceb0505c8bbc1e..65de4f641a550f5a3396aef065aa5b757c16f304 100644 (file)
@@ -1,11 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <object class="GtkAdjustment" id="scale_adjustment">
-    <property name="lower">1</property>
-    <property name="upper">2</property>
-    <property name="step-increment">1</property>
-    <property name="page-increment">1</property>
-  </object>
   <template class="GtkInspectorGeneral" parent="GtkBox">
     <property name="orientation">vertical</property>
     <property name="margin">60</property>
         </child>
       </object>
     </child>
-    <child>
-      <object class="GtkFrame" id="settings_frame">
-        <property name="visible">True</property>
-        <property name="halign">center</property>
-        <child>
-          <object class="GtkListBox">
-            <property name="visible">True</property>
-            <property name="selection-mode">none</property>
-            <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-                <property name="margin">10</property>
-                <property name="spacing">40</property>
-                <child>
-                  <object class="GtkLabel" id="hidpi_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Window scaling</property>
-                    <property name="halign">start</property>
-                    <property name="valign">baseline</property>
-                    <property name="xalign">0.0</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSpinButton" id="hidpi_spin">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="valign">baseline</property>
-                    <property name="adjustment">scale_adjustment</property>
-                    <property name="snap-to-ticks">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-                <property name="margin">10</property>
-                <property name="spacing">40</property>
-                <child>
-                  <object class="GtkLabel" id="touchscreen_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Simulate touchscreen</property>
-                    <property name="halign">start</property>
-                    <property name="valign">baseline</property>
-                    <property name="xalign">0.0</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSwitch" id="touchscreen_switch">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="valign">baseline</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
   </template>
   <object class="GtkSizeGroup">
     <property name="mode">horizontal</property>
       <widget name="gtk_exe_prefix_label"/>
       <widget name="gtk_data_prefix_label"/>
       <widget name="gsettings_schema_dir_label"/>
-      <widget name="touchscreen_label"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup">
     <widgets>
       <widget name="version_frame"/>
       <widget name="env_frame"/>
-      <widget name="settings_frame"/>
     </widgets>
   </object>
 </interface>
index a665b5b7acf0cde0a5e0475249c0f50f5add4811..9af48530feb2a5549b1fcc97173f0fa175abd47e 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "visual.h"
 
+#include "gtkadjustment.h"
+#include "gtkbox.h"
 #include "gtkcomboboxtext.h"
 #include "gtkdebug.h"
 #include "gtkprivate.h"
 #include "gtkswitch.h"
 #include "gtkwindow.h"
 
+#ifdef GDK_WINDOWING_X11
+#include "x11/gdkx.h"
+#endif
+
 struct _GtkInspectorVisualPrivate
 {
+  GtkWidget *visual_box;
+  GtkWidget *theme_combo;
+  GtkWidget *dark_switch;
+  GtkWidget *icon_combo;
   GtkWidget *direction_combo;
+  GtkWidget *hidpi_spin;
+  GtkAdjustment *scale_adjustment;
+
+  GtkWidget *debug_box;
   GtkWidget *updates_switch;
   GtkWidget *baselines_switch;
   GtkWidget *pixelcache_switch;
+  GtkWidget *touchscreen_switch;
 
-  GtkWidget *theme_combo;
-  GtkWidget *dark_switch;
-  GtkWidget *icon_combo;
+  GtkAdjustment *focus_adjustment;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_SCROLLED_WINDOW)
 
 static void
 fix_direction_recurse (GtkWidget *widget,
@@ -325,6 +338,116 @@ icons_changed (GtkComboBox        *c,
   g_free (theme);
 }
 
+#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
+static void
+scale_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
+{
+  GdkDisplay *display;
+  gint scale;
+
+  scale = gtk_adjustment_get_value (adjustment);
+  display = gtk_widget_get_display (GTK_WIDGET (vis));
+  gdk_x11_display_set_window_scale (display, scale);
+}
+#endif
+
+static void
+init_scale (GtkInspectorVisual *vis)
+{
+#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
+  GdkScreen *screen;
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (vis));
+  if (GDK_IS_X11_SCREEN (screen))
+    {
+      gdouble scale;
+
+      scale = gdk_screen_get_monitor_scale_factor (screen, 0);
+      gtk_adjustment_set_value (vis->priv->scale_adjustment, scale);
+      g_signal_connect (vis->priv->scale_adjustment, "value-changed",
+                        G_CALLBACK (scale_changed), vis);
+    }
+  else
+#endif
+    {
+      gtk_adjustment_set_value (vis->priv->scale_adjustment, 1);
+      gtk_widget_set_sensitive (vis->priv->hidpi_spin, FALSE);
+      gtk_widget_set_tooltip_text (vis->priv->hidpi_spin,
+                                   _("Backend does not support window scaling"));
+    }
+}
+
+static void
+update_touchscreen (GtkSwitch *sw)
+{
+  GtkDebugFlag flags;
+
+  flags = gtk_get_debug_flags ();
+
+  if (gtk_switch_get_active (sw))
+    flags |= GTK_DEBUG_TOUCHSCREEN;
+  else
+    flags &= ~GTK_DEBUG_TOUCHSCREEN;
+
+  gtk_set_debug_flags (flags);
+}
+
+static void
+init_touchscreen (GtkInspectorVisual *vis)
+{
+  gtk_switch_set_active (GTK_SWITCH (vis->priv->touchscreen_switch), (gtk_get_debug_flags () & GTK_DEBUG_TOUCHSCREEN) != 0);
+  g_signal_connect (vis->priv->touchscreen_switch, "notify::active",
+                    G_CALLBACK (update_touchscreen), NULL);
+
+  if (g_getenv ("GTK_TEST_TOUCHSCREEN") != 0)
+    {
+      /* hardcoded, nothing we can do */
+      gtk_switch_set_active (GTK_SWITCH (vis->priv->touchscreen_switch), TRUE);
+      gtk_widget_set_sensitive (vis->priv->touchscreen_switch, FALSE);
+      gtk_widget_set_tooltip_text (vis->priv->touchscreen_switch, _("Setting is hardcoded by GTK_TEST_TOUCHSCREEN"));
+    }
+}
+
+static gboolean
+keynav_failed (GtkWidget *widget, GtkDirectionType direction, GtkInspectorVisual *vis)
+{
+  GtkWidget *next;
+  gdouble value, lower, upper, page;
+
+  if (direction == GTK_DIR_DOWN &&
+      widget == vis->priv->visual_box)
+    next = vis->priv->debug_box;
+  else if (direction == GTK_DIR_UP &&
+           widget == vis->priv->debug_box)
+    next = vis->priv->visual_box;
+  else 
+    next = NULL;
+
+  if (next)
+    {
+      gtk_widget_child_focus (next, direction);
+      return TRUE;
+    }
+
+  value = gtk_adjustment_get_value (vis->priv->focus_adjustment);
+  lower = gtk_adjustment_get_lower (vis->priv->focus_adjustment);
+  upper = gtk_adjustment_get_upper (vis->priv->focus_adjustment);
+  page  = gtk_adjustment_get_page_size (vis->priv->focus_adjustment);
+
+  if (direction == GTK_DIR_UP && value > lower)
+    {
+      gtk_adjustment_set_value (vis->priv->focus_adjustment, lower);
+      return TRUE;
+    }
+  else if (direction == GTK_DIR_DOWN && value < upper - page)
+    {
+      gtk_adjustment_set_value (vis->priv->focus_adjustment, upper - page);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gtk_inspector_visual_init (GtkInspectorVisual *vis)
 {
@@ -334,12 +457,32 @@ gtk_inspector_visual_init (GtkInspectorVisual *vis)
   init_theme (vis);
   init_dark (vis);
   init_icons (vis);
+  init_scale (vis);
+  init_touchscreen (vis);
+}
+
+static void
+gtk_inspector_visual_constructed (GObject *object)
+{
+  GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (object);
+
+  G_OBJECT_CLASS (gtk_inspector_visual_parent_class)->constructed (object);
+
+  vis->priv->focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (vis));
+  gtk_container_set_focus_vadjustment (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (vis))),
+                                       vis->priv->focus_adjustment);
+
+   g_signal_connect (vis->priv->visual_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
+   g_signal_connect (vis->priv->debug_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
 }
 
 static void
 gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = gtk_inspector_visual_constructed;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/visual.ui");
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, updates_switch);
@@ -349,6 +492,11 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, dark_switch);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, theme_combo);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, icon_combo);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, hidpi_spin);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, scale_adjustment);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, touchscreen_switch);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, visual_box);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, debug_box);
 
   gtk_widget_class_bind_template_callback (widget_class, updates_activate);
   gtk_widget_class_bind_template_callback (widget_class, direction_changed);
@@ -356,7 +504,6 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, pixelcache_activate);
   gtk_widget_class_bind_template_callback (widget_class, theme_changed);
   gtk_widget_class_bind_template_callback (widget_class, icons_changed);
-
 }
 
 // vim: set et sw=2 ts=2:
index 593be52b3252d365e39ce36d827685efff108a16..90df94f0347924da70b46b14eb36f5e4b173c656 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _GTK_INSPECTOR_VISUAL_H_
 #define _GTK_INSPECTOR_VISUAL_H_
 
-#include <gtk/gtkbox.h>
+#include <gtk/gtkscrolledwindow.h>
 
 #define GTK_TYPE_INSPECTOR_VISUAL            (gtk_inspector_visual_get_type())
 #define GTK_INSPECTOR_VISUAL(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_VISUAL, GtkInspectorVisual))
@@ -32,13 +32,13 @@ typedef struct _GtkInspectorVisualPrivate GtkInspectorVisualPrivate;
 
 typedef struct _GtkInspectorVisual
 {
-  GtkBox parent;
+  GtkScrolledWindow parent;
   GtkInspectorVisualPrivate *priv;
 } GtkInspectorVisual;
 
 typedef struct _GtkInspectorVisualClass
 {
-  GtkBoxClass parent;
+  GtkScrolledWindowClass parent;
 } GtkInspectorVisualClass;
 
 G_BEGIN_DECLS
index 5233c9403a4bc4c229ce1d24b64e822559d81a92..499bc4ad1072dcc601487fbb87ce786fa7e8981a 100644 (file)
@@ -1,6 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <template class="GtkInspectorVisual" parent="GtkBox">
+  <object class="GtkAdjustment" id="scale_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">2</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">1</property>
+  </object>
+  <template class="GtkInspectorVisual" parent="GtkScrolledWindow">
+    <property name="hscrollbar-policy">never</property>
+    <property name="vscrollbar-policy">automatic</property>
+    <child>
+      <object class="GtkBox">
+    <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <property name="margin">60</property>
     <property name="spacing">10</property>
@@ -9,9 +20,12 @@
         <property name="visible">True</property>
         <property name="halign">center</property>
         <child>
-          <object class="GtkListBox">
+          <object class="GtkListBox" id="visual_box">
             <property name="visible">True</property>
             <property name="selection-mode">none</property>
+            <style>
+              <class name="view"/>
+            </style>
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <property name="margin">10</property>
+                <property name="spacing">40</property>
+                <child>
+                  <object class="GtkLabel" id="hidpi_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Window scaling</property>
+                    <property name="halign">start</property>
+                    <property name="valign">baseline</property>
+                    <property name="xalign">0.0</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="hidpi_spin">
+                    <property name="visible">True</property>
+                    <property name="halign">end</property>
+                    <property name="valign">baseline</property>
+                    <property name="adjustment">scale_adjustment</property>
+                    <property name="snap-to-ticks">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
         <property name="visible">True</property>
         <property name="halign">center</property>
         <child>
-          <object class="GtkListBox">
+          <object class="GtkListBox" id="debug_box">
             <property name="visible">True</property>
             <property name="selection-mode">none</property>
             <child>
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <property name="margin">10</property>
+                <property name="spacing">40</property>
+                <child>
+                  <object class="GtkLabel" id="touchscreen_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Simulate touchscreen</property>
+                    <property name="halign">start</property>
+                    <property name="valign">baseline</property>
+                    <property name="xalign">0.0</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSwitch" id="touchscreen_switch">
+                    <property name="visible">True</property>
+                    <property name="halign">end</property>
+                    <property name="valign">baseline</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
     </child>
+      </object>
+    </child>
   </template>
   <object class="GtkSizeGroup">
     <property name="mode">horizontal</property>
       <widget name="dark_label"/>
       <widget name="icon_label"/>
       <widget name="direction_label"/>
+      <widget name="hidpi_label"/>
       <widget name="updates_label"/>
       <widget name="baselines_label"/>
       <widget name="pixelcache_label"/>
+      <widget name="touchscreen_label"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup">